<%@page import="cz.tpj.logic.*" %>
<%@page import="cz.tpj.database.bod_zaujmu.*"%>
<%@page import="cz.tpj.util.*"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.Iterator"%>

<%
final String ACTION = "action";
final String NONE = "none";
final String ATTRACTIVE_PLACES = "selected_a_p";
String message = new String();

//akce podle zvoleneho tlacitka
String action = request.getParameter(ACTION);
//vybrane mesto v comboBoxu
String interestId = request.getParameter(ATTRACTIVE_PLACES);
//ukaz jestlize je zmacknuto tlacitko zobrezit a je vybrano alespon jedno mesto
if(action != null && interestId != null){
	//pokud nebylo nic zvoleno, pak se nastavi message
	if(interestId.equals(NONE)){
		message = "<p>Musíte nejprve zvolit nějaké místo k smazání!</p>";
	}else{
		try{
			Table_Bod_zaujmu.getInstance().deleteBodZaujmu(Integer.parseInt(interestId));
			message = "<p>Místo bylo úspěšně odebráno.</p>";
		}catch(ErrorDatabase e){
			message = e.getMessage();
		}
	}
}
%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <%= Navigation.getHead(null) %>
    <%= Navigation.getStartBody() %>
    <%= Navigation.getNavigationPanel(null, request) %>
          
        <div id="<%= Navigation.DIV_CENTER %>">
            <h1>Odstraň bod zájmu</h1>
            <%= message %>
          	<form method="POST" action="<%= Navigation.JSP_DEL_ATTRACTIVE_PLACE%>">
	          	<select name="<%=ATTRACTIVE_PLACES %>">
	          		<!-- defoultni polozka-vybidnuti k vybrani mesta -->
	          		<option value='<%= NONE %>'>vyber místo</option>
		          	<%
		          	//------------------najde vsecky zajimavosti-----------------------
		          	ArrayList<Bod_zaujmu> all_atractives = Table_Bod_zaujmu.getInstance().getAllInterests();
		          	Iterator<Bod_zaujmu> it = all_atractives.iterator();
		          	//pomocna promenna
		          	Bod_zaujmu attractive_place = null;
		          	//nacti posledne zvolenou zajimavost
		        	String selectedId = request.getParameter(ATTRACTIVE_PLACES);
		          	//projde vsecky zajmavosti a zapise jejich nazev do ComboBoxu
		          	
		          	while(it.hasNext()){
		          		attractive_place = it.next();
		          		out.println("<option value='" + attractive_place.getId() + "'>" + attractive_place.getNazov() + "</option> ");
		          	}
		          	%>
	          	</select>
	          	<input type="submit" name="<%= ACTION %>" value="Smaž">
          	</form>
        </div>
 	
 	<%= Navigation.getLoginLink(request) %>
</html>